/*
 * Copyright 2020-2025 the original author or authors.
 * You cannot use this file unless authorized by the author.
 */
package org.ipig.commons.context;

import org.ipig.commons.helper.AssertHelper;
import org.ipig.commons.helper.StringHelper;
import org.ipig.constants.JavaCnst;

import java.io.File;

/**
 * JavaContext
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id: JavaContext.java 3 2020-01-21 09:36:33Z ts <comchnts@163.com> $$
 * @since 1.0
 */
public class JavaContext {
    /**
     * getJavaHome
     *
     * @return
     */
    public static String getJavaHome() {
        String javaHome = System.getenv(JavaCnst.ENV_JAVA_HOME);
        AssertHelper.hasText(javaHome, "Set the ENV_JAVA_HOME environment variable!");
        return javaHome;
    }

    /**
     * getJavaCmd
     *
     * @return
     */
    public static String getJavaCmd() {
        return StringHelper.join(File.separator, getJavaHome(), "bin", "java");
    }

    /**
     * getIoTmpDir
     *
     * @return
     */
    public static String getIoTmpDir() {
        return System.getProperty(JavaCnst.IO_TMP_DIR);
    }

    /**
     * 操作系统的名称
     *
     * @return
     */
    public static String getOsName() {
        return System.getProperty(JavaCnst.OS_NAME);
    }

    /**
     * 操作系统的版本
     *
     * @return
     */
    public static String getOsVersion() {
        return System.getProperty(JavaCnst.OS_VERSION);
    }
}
